package view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

//用户头像面板类
public class CompositeUser {
	private Composite composite;
	private Label lbl_head;
	private Label lbl_name;
	private Label lbl_talk;
	
	//private Label lbl_blackHead;
	public CompositeUser(int cX, int cY, Composite com, Cursor cursor){
		
		composite = new Composite(com, SWT.BORDER);
		composite.setBounds(cX,cY,45,45);
		
		lbl_name =  new Label(composite, SWT.NONE); 
		lbl_name.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lbl_name.setAlignment(SWT.CENTER);
		lbl_name.setFont(SWTResourceManager.getFont("微软雅黑", 8, SWT.NORMAL));
		lbl_name.setBounds(0, 25, 45, 16);
		
		
		lbl_talk = new Label(composite, SWT.NONE);
		lbl_talk.setAlignment(SWT.CENTER);
		lbl_talk.setLocation(26, 5);
		lbl_talk.setSize(15, 15);
		lbl_talk.setImage(SWTResourceManager.getImage(GMS.class, "/img/CD_14.png"));
		
		lbl_head = new Label(composite, SWT.NONE);
		lbl_head.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				if(!lbl_name.getForeground().equals(SWTResourceManager.getColor(SWT.COLOR_RED))){
					lbl_name.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
				}
			}
			@Override
			public void mouseExit(MouseEvent e) {
				if(!lbl_name.getForeground().equals(SWTResourceManager.getColor(SWT.COLOR_RED))){
					lbl_name.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
				}
			}
		});
		
		lbl_head.setImage(SWTResourceManager.getImage(GMS.class, "/img/user_25.png"));
		lbl_head.setBounds(1, 1, 25, 25);
		lbl_head.setCursor(cursor);
		
		/*lbl_blackHead = new Label(composite, SWT.NONE);
		lbl_blackHead.setImage(SWTResourceManager.getImage(GMS.class, "/img/user_25_black.png"));
		lbl_blackHead.setBounds(1, 1, 25, 25);*/
	}
	
	//设置绿色说话按钮
	public void setTalkImage(){
		lbl_talk.setImage(SWTResourceManager.getImage(GMS.class, "/img/cd_green_13.png"));
	}
	//设置白色沉默按钮
	public void setQuietImage(){
		lbl_talk.setImage(SWTResourceManager.getImage(GMS.class, "/img/CD_14.png"));
	}
	//设置名字
	public void setName(String string){
		lbl_name.setText(string);
	}
	//设置没人的情况
	public void setNone(){	
		//lbl_blackHead.setVisible(true);
		
		lbl_name.setVisible(false);
		lbl_talk.setVisible(false);
		lbl_head.setVisible(false);
	}
	//设置可见
	public void setVis(){
		//lbl_blackHead.setVisible(false);
	
		lbl_name.setVisible(true);
		lbl_talk.setVisible(true);
		lbl_head.setVisible(true);
	}
	//获得组建中的头像label
	public Label getHead(){
		return lbl_head;
	}
	//是否为空
	public boolean isNone(){
		if(composite.isVisible()){
			return false;
		}
		else{
			return true;
		}
	}
	//获得焦点
	public void setFocus(){
		lbl_head.setImage(SWTResourceManager.getImage(GMS.class, "/img/user office_25.png"));
		lbl_name.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
	}
	//失去焦点
	public void lostFocus(){
		lbl_head.setImage(SWTResourceManager.getImage(GMS.class, "/img/user_25.png"));
		lbl_name.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
	}
	//组建消除
	public void cuDispose(){
		composite.dispose();
		//lbl_blackHead.dispose();
		lbl_head.dispose();
		lbl_name.dispose();
		lbl_talk.dispose();
	}
	
}
